/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.server.service;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.util.List;
import org.lucava.boatskeeper.client.service.UserService;
import org.lucava.boatskeeper.server.dao.MockUserDao;
import org.lucava.boatskeeper.shared.dto.UserDto;

/**
 *
 * @author glenn
 */
public class UserServiceImpl extends RemoteServiceServlet implements UserService {

    @Override
    public List<UserDto> getUsers() {
        return MockUserDao.getAll();
    }

    @Override
    public UserDto getUser(Integer id) {
        return MockUserDao.get(id);
    }

    @Override
    public Boolean saveUser(UserDto user) {
        if (user.getId() == null) {
            MockUserDao.add(user);
        } else {
            MockUserDao.save(user);
        }

        return true;
    }

    @Override
    public Boolean removeUser(UserDto user) {
        MockUserDao.delete(user);
        return true;
    }

    @Override
    public Boolean removeUsers(List<Integer> userIds) {

        for (Integer id : userIds) {
            MockUserDao.delete(MockUserDao.get(id));
        }

        return true;
    }
}
